package listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import database.DBmanager;

/**
 * Application Lifecycle Listener implementation class ServletcontextListener
 *
 */
public class ServletcontextListener implements ServletContextListener {

    /**
     * Default constructor. 
     */
    public ServletcontextListener() {
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent arg0) {
        ServletContext context = arg0.getServletContext();
        String dbname = context.getInitParameter("dbpath");
        
        DBmanager dbmanager = DBmanager.getInstance();
        dbmanager.setInit(dbname);
        
        if(context.getAttribute("dbmanager") == null){
			context.setAttribute("dbmanager", dbmanager);
		}
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent arg0) {
        // TODO Auto-generated method stub
    }
	
}
